#Region " Imports "

Imports System
Imports System.Data
Imports BA
Imports BA.DAL

#End Region

Partial Class indexing
    Inherits WebPageBase

#Region " Enums, Memebers and Properties "

    Private Enum AccessType
        All = -1
        PrivateOnly = 1
        PublicOnly = 2
    End Enum

    Private Enum Status
        All = -1
        Enabled = 6
    End Enum

    Private Config As New WebConfigSettings

#End Region

#Region " Page Events "

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Me.Page.IsPostBack = False Then
            LoadGrid(0)
        End If
    End Sub

#End Region

#Region " Save Data "



#End Region

#Region " Load Data "

    Private Sub LoadGrid(ByVal Index As Integer)
        Dim DT As New DataTable
        Dim DAL As New BA.DAL.DBUtility

        DAL.CreateDBObjects(Config.ConnectionString, Config.Provider)

        If PublicOnly() = True Then
            DAL.AddParameter("@accesstype", AccessType.PublicOnly)
        ElseIf PrivateOnly() = True Then
            DAL.AddParameter("@accesstype", AccessType.PrivateOnly)
        Else
            DAL.AddParameter("@accesstype", AccessType.All)
        End If

        If ShowAll() = True Then
            DAL.AddParameter("@status", Status.All)
        Else
            DAL.AddParameter("@status", Status.Enabled)
        End If

        DAL.AddParameter("@currentdate", Date.Now())

        DT = DAL.GetDataTable("SELECT pageid, title FROM page WHERE (convert(varchar, expiredate, 110) <= convert(varchar, @currentdate, 110)) AND (iv_status = @status or @status = -1) and (iv_access_type = @accesstype or @accesstype = -1)", CommandType.Text, ConnectionState.Open)

        With Me.uxIndexingGridView
            .DataSource = DT
            .PageIndex = Index
            .PageSize = PageSize()
            .DataBind()
        End With

    End Sub

#End Region

#Region " Form Controls Events "

    Protected Sub uxIndexingGridView_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles uxIndexingGridView.PageIndexChanging
        LoadGrid(e.NewPageIndex)
    End Sub

#End Region

#Region " Helpers and Methods "

    Private Function PublicOnly() As Boolean
        Return GetBooleanFromQueryString("publiconly")
    End Function

    Private Function PrivateOnly() As Boolean
        Return GetBooleanFromQueryString("privateonly")
    End Function

    Private Function ShowAll() As Boolean
        Return GetBooleanFromQueryString("showall")
    End Function

    Private Function PageSize() As Integer

        If GetIntegerFromQueryString("pagesize") = 0 Then
            Return 10
        Else
            Return GetIntegerFromQueryString("pagesize")
        End If

    End Function

#End Region

End Class
